package com.example.baselibrary.db.dao;

import com.example.baselibrary.db.BTDBHelper;
import com.example.baselibrary.db.table.AttentionTable;

import java.sql.SQLException;
import java.util.Collection;

import cc.vv.lklibrary.db.dao.DBBaseTableDao;
import cc.vv.lklibrary.db.help.DBBaseOpenHelper;

/**
 * 特别关注
 *
 * @author: NPF
 * @date: 2018/4/12.
 */
public class AttentionDao extends DBBaseTableDao<AttentionTable, String> {
    public AttentionDao(DBBaseOpenHelper openHelper) {
        super(openHelper);
    }

    private static AttentionDao mInstance;

    /**
     * 单例模式获取实例
     */
    public static AttentionDao getInstance() {
        if (null == mInstance) {
            synchronized (AttentionDao.class) {
                if (null == mInstance) {
                    mInstance = new AttentionDao(BTDBHelper.getInstance());
                }
            }
        }
        return mInstance;
    }

    /**
     * 批量插入
     *
     * @param isClearTable 是否删除表数据
     * @param collection
     * @return
     */
    public int create(boolean isClearTable, Collection<AttentionTable> collection) {
        int result = -1;
        try {
            if (isClearTable) {
                mDao.deleteBuilder().delete();
            }
            result = mDao.create(collection);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return result;
    }
}
